import {createRouter, createWebHashHistory} from 'vue-router'

import Header from '../components/Header.vue'
import Login from '../components/Login.vue'
import Register from '../components/Register.vue'
import ShowSchedule from '../components/ShowSchedule.vue'
import myPinia from '../myPinia'
import { defineUser } from '../store/logUserStore'

let sysUser = defineUser(myPinia)

const router = createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:'/',
            redirect: '/showSchedule'
        },
        {
            path:'/showSchedule',
            component:ShowSchedule
        },{
            path:'/login',
            component:Login
        },
        {
            path:'/register',
            component:Register
        },
    ]
})

router.beforeEach((to, form, next) => {
    if(to.path == '/showSchedule') {
        if(sysUser.username == '') {
            alert('您还未登录，请先登录！')
            next('/login')
        } else{
            next()
        }
    } else{
        next()
    }
})

export default router